var btn = document.getElementById("btn")
var username = document.getElementById("username")
var password = document.getElementById("password")
var rpassword = document.getElementById("rpassword")
var nickname = document.getElementById("nickname")

btn.onclick = async function(){
      //发起请求先明确几件事情
      //1.请求路径
      //2.请求方式
      //3.请求参数
let url = "http://127.0.0.1:8888/users/register"
let options = {
      method:"POST",
      headers:{
            "Content-Type":"application/x-www-form-urlencoded"
      },body:`username=${username.value}&password=${password.value}&rpassword=${rpassword.value}&nickname=${nickname.value}`

     
};
let response = await fetch(url,options);
let data = await response.json();
console.log(data);
//注册结束之后我们应该跳转到登录页面
if(data.code ===1){
      alert("注册成功，马上为您跳转到登录页面");
      setTimeout(() => {
            location.href = "loginin.html"
            
      }, 2000);
     
}else{
      alert(data.message)
}

}